{extend name="layout"/}

{block name="content"}

<div class="panel">
    <div class="panel-heading">
        <div class="panel-title">编辑【绝缘产品库】下的内容</div>
    </div>
    <style>
        .configImage,.configFile{min-height:100px; padding-bottom: 20px; }
        .configFile .dz-thumbnail{display:none}
        .dz-default.dz-message{
            right: auto;
            left: 50%;
            top: 25px;
            transform: none;
            padding-left: 0;
            font-size: 35px;
            font-weight: 400;
            line-height: 35px;
            position: relative
        }
        .edui-default * {color:#333}
    </style>
    <link rel="stylesheet" type="text/css" href="__STATIC__/semantic/semantic.min.css">
    <script src="__STATIC__/semantic/semantic.min.js"></script>

 <!--<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet">
  <script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.js"></script>
 -->
    <form class="panel-body" method="post" action="{:url('edit',['id'=>$plist.id])}">

        <fieldset class="form-group">
            <label style="clear:both; display: block">供求分类</label>
            <label class="custom-control custom-radio radio-inline">
                <input type="radio" name="modelField[class]" class="custom-control-input" value="0" {if $plist.class=="0"}checked{/if}>
                <span class="custom-control-indicator"></span>供应    
            </label>
            <label class="custom-control custom-radio radio-inline">
                <input type="radio" name="modelField[class]" class="custom-control-input" value="1" {if $plist.class=="1"}checked{/if}>
                <span class="custom-control-indicator"></span>求购    
            </label>
        </fieldset>
        <fieldset class="form-group">
            <label>选择产品类别*</label>
            <select id="modelField[typeid]" name="modelField[typeid]" class="form-control" style="width: 100%" data-allow-clear="true" tabindex="-1">
                <option></option>
                {volist name="tlist" id="vo"}
                <option value="{$vo.id}" {if $plist.typeid==$vo.id}selected{/if}>{:str_repeat('┝┈┈', $vo['deep']-1)}{$vo.title}</option>
                {/volist}
            </select>
        </fieldset>
        
        <fieldset class="form-group">
            <label style="clear:both; display: block">产品名称*</label>
            <input type="text" class="form-control" name="modelField[title]" placeholder="请输入产品名称" value="{$plist.title }">
        </fieldset>
        <fieldset class="form-group">
            <label style="clear:both; display: block">产品图片</label>
            <input type="hidden" name="modelField[pictures]" value="{$plist['pictures']}">
            <div id="modelFieldpictures" class="configImage b-a-2 border-default" {if $plist.attachment!=[]} data-imgurl="__UPLOAD__/{$plist.attachment.path}" data-imgsize="{$plist.attachment.size}" data-imgname="{$plist.attachment.name}"{/if}>
                <div class="dz-default dz-message text-light">
                    <i class="fa fa-plus"></i>
                </div>
            </div>
            <script>
                $(function () {
                    var thisdom = $('#modelFieldpictures');
                    var inputdom = thisdom.prev('input');
                    var nowPicid=inputdom.val();
                    var files={};
                    if(''!=inputdom.val()){
                        $.ajax({
                            url : "/admin.php/member/filemanage/ajaxgetfileinfo.html",
                            type : 'post',
                            dataType: "json",
                            async: false,
                            data : {ids: nowPicid},
                            success : function(data){
                               if (''!=data) {
                                  files=data;
                               }
                            }
                        });
                    }
                    thisdom.dropzone({
                        url: "/admin.php/member/filemanage/upload/dir/images/module/admin.html",
                        dictRemoveFile: "删除图片",
                        init: function () {
                            //回调已上传图片
                             if (!jQuery.isEmptyObject(files)) {
                                var mockFile = {
                                    name: files.name,
                                    size: files.size,
                                    accepted: true,
                                    status: 'success',
                                    processing: false
                                };
                                this.options.addedfile.call(this, mockFile);
                                this.options.thumbnail.call(this, mockFile, '/public/uploads/'+files.path);
                                this.files[0] = mockFile;
                                delImgEvent(thisdom);
                            }
                        },
                        resize: function (file) {
                            return {
                                srcX: 0,
                                srcY: 0,
                                srcWidth: file.width,
                                srcHeight: file.height,
                                trgWidth: file.width,
                                trgHeight: file.height
                            };
                        },
                        maxFiles: 1,
                        maxfilesexceeded: function (file) {
                            this.removeAllFiles();
                            this.addFile(file);
                        },
                        success: function (file, response, e) {
                            //移除当前图片 
                            //thisdom.find('div.dz-preview:not(.dz-processing)').remove();
                            if (response.status == 1) {
                                inputdom.attr('value', response.id);
                                delImgEvent(thisdom);
                                toastr['success'](response.info, '', {
                                    closeButton: true
                                });
                            } else {
                                var data = response.info;
                                if (!data) {
                                    data = '未知错误：' + response;
                                }
                                toastr['error'](data, '', {
                                    closeButton: true
                                });
                                //移除当前图片恢复之前图片
                                this.removeFile(file);
                                 if (!jQuery.isEmptyObject(files)) {
                                    var mockFile = {
                                          name: files.name,
                                          size: files.size,
                                          accepted: true,
                                          status: 'success',
                                          processing: false
                                    };
                                    this.options.addedfile.call(this, mockFile);
                                    this.options.thumbnail.call(this, mockFile, '/public/uploads/'+files.path);
                                    this.files[0] = mockFile;
                                    delImgEvent(thisdom);
                                }
                            }
                        }
                    });
                    function delImgEvent(dom) {
                        dom.find('.dz-remove').click(function () {
                            bootbox.confirm({
                                message: '只从这里删除,但仍然保留在服务器中？',
                                className: 'bootbox-sm',
                                buttons: {
                                       confirm: {
                                            label: '是的',
                                            className: 'btn-success'
                                        },
                                        cancel: {
                                            label: '从服务器删除',
                                            className: 'btn-default'
                                        }
                                },
                                callback: function (result) {
                                    if (!result) {
                                        var id = inputdom.attr('value');
                                        $.get("/admin.php/member/filemanage/delete.html", {id: id},
                                                function (data) {
                                                    if (data === 'true') {
                                                        toastr['success']('图片删除成功~', '', {
                                                            closeButton: true
                                                        });
                                                    } else {
                                                        toastr['error'](data, '', {
                                                            closeButton: true
                                                        });
                                                    }
                                                },
                                                "text"
                                                );
                                    }
                                    inputdom.attr('value','');
                                }
                            });
                        });
                    }
                });
            </script>
        </fieldset>
        <fieldset class="form-group">
            <label style="clear:both; display: block">信息详情</label>
            <textarea class="form-control" id="modelFieldsupplyinfo" name="modelField[supplyinfo]" placeholder="请输入供应信息" style="display: none;">{$plist.supplyinfo}</textarea>
        </fieldset>
        <script>
          $(function() {
              $('#modelFieldsupplyinfo').summernote({
                height: 200,
                toolbar: [
                  ['parastyle', ['style']],
                  ['fontstyle', ['fontname', 'fontsize']],
                  ['style', ['bold', 'italic', 'underline', 'clear']],
                  ['font', ['strikethrough', 'superscript', 'subscript']],
                  ['color', ['color']],
                  ['para', ['ul', 'ol', 'paragraph']],
                  ['height', ['height']],
                  ['insert', ['link', 'video', 'table', 'hr']],
                  ['history', ['undo', 'redo']],
                  ['misc', ['codeview', 'fullscreen']],
                  ['help', ['help']]
                ],
                lang: 'zh-CN'
              });
            });
        </script>
        <div class="panel-footer text-right">
            <input type="submit" class="btn btn-primary" value="确认编辑">
        </div>
    </form>
</div>

{/block}